package com.ss.android.update;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;
import com.bytedance.common.utility.collection.WeakHandler.Callback;
import com.bytedance.common.utility.collection.WeakHandler;
import com.ss.android.article.browser.R;
import com.ss.android.common.lib.MobClickCombiner;

public final class h extends Dialog implements Callback {
    static final class h$a extends Thread {
        private final h c;
        private com.ss.android.update.a a;
        private volatile boolean b;

        h$a(h arg2) {
            this.c = arg2;
            this.a = new com.ss.android.update.a();
            this.b = false;
        }

        public final void run() {
            com.ss.android.update.a v2;
            while(true) {
                long v0 = 1500;
                try {
                    Thread.sleep(v0);
                }
                catch(Exception v0_1) {
                }

                if(!this.c.a.g()) {
                    break;
                }

                UpdateHelper v0_2 = this.c.a;
                com.ss.android.update.a v1 = this.a;
                v2 = v0_2.n;
                synchronized (v2){
                    v1.a = v0_2.n.a;
                    v1.b = v0_2.n.b;
                }

                Message v0_4 = this.c.b.obtainMessage(1);
                v0_4.arg1 = this.a.a;
                v0_4.arg2 = this.a.b;
                synchronized (this){
                    this.c.b.sendMessage(v0_4);
                    continue;
                }
            }
            this.c.b.sendEmptyMessage(2);
            return;
        }
    }

    UpdateHelper a;
    Handler b;
    private TextView c;
    private TextView d;
    private TextView e;
    private View f;
    private View g;
    private View h;
    private TextView i;
    private TextView j;
    private TextView k;
    private TextView l;
    private boolean m;
    private String n;

    public h(Context arg2) {
        super(arg2);
        this.n = "upgrade_pop";
        new i();
        this.m = true;
    }

    private void a() {
        int v8;
        boolean v1 = true;
        int v6 = View.GONE;
        UpdateHelper v9 = UpdateHelper.getInstance();
        this.a = v9;
        if(v9 != null) {
            boolean v0 = v9.r() != null ? true : false;
            boolean v10 = v9.q();
            if(!v9.m() || !this.m) {
                v1 = false;
            }

            String v5 = UpdateHelper.a(v9.f());
            String v4 = v9.n();
            String v11 = v9.o();
            int v7 = R.string.label_update_immediately;
            int v3 = R.string.label_update_later;
            if(v1) {
                v3 = v0 ? R.string.label_update_install : R.string.label_update_now;
                v7 = R.string.label_update_exit;
                v8 = v3;
            }
            else {
                v8 = v7;
                v7 = v3;
            }

            String v3_1 = v0 ? v4 : v5;
            this.c.setText(((CharSequence)v11));
            TextView v5_1 = this.d;
            int v4_1 = v10 ? View.VISIBLE : v6;
            v5_1.setVisibility(v4_1);
            this.e.setText(((CharSequence)v3_1));
            this.i.setText(v8);
            this.l.setText(v7);
            this.i.setVisibility(View.VISIBLE);
            this.g.setVisibility(View.VISIBLE);
            this.h.setVisibility(v6);
            this.k.setVisibility(v6);
            this.j.setVisibility(v6);
            this.l.setOnClickListener(new j(this, v1, v0));
            this.f.setOnClickListener(new k(this, v1, v0, v9));
        }
    }

    final void a(String arg3) {
        if(this.getContext() != null) {
            MobClickCombiner.onEvent(this.getContext(), this.n, arg3);
        }
    }

    public final void handleMsg(Message message) {
        int v0 = 99;
        int v5 = View.GONE;
        int v1 = 0;
        switch(message.what) {
            case 1: {
                int v2 = message.arg1;
                int v3 = message.arg2;
                this.i.setVisibility(v5);
                this.g.setVisibility(v5);
                this.h.setVisibility(View.VISIBLE);
                this.k.setVisibility(View.VISIBLE);
                this.j.setVisibility(View.VISIBLE);
                if(v2 > 0) {
                    v1 = 5;
                }

                if(v3 > 0) {
                    v1 = v2 * 100 / v3;
                    if(v1 <= v0) {
                        v0 = v1;
                    }
                }
                else {
                    v0 = v1;
                }

                this.j.setText(v0 + "%");
                break;
            }
            case 2: {
                this.a();
                break;
            }
        }
    }

    protected final void onCreate(Bundle arg6) {
        int v1 = 1;
        super.onCreate(arg6);
        this.requestWindowFeature(1);
        this.setContentView(com.ss.android.article.browser.R.layout.j8);
        this.getWindow().setBackgroundDrawableResource(com.ss.android.article.browser.R.drawable.e);
        this.getWindow().setLayout(-2, -2);
        this.getWindow().setGravity(17);
        this.setCancelable(false);
        this.setCanceledOnTouchOutside(false);
        this.b = new WeakHandler(((Callback)this));
        this.c = this.findViewById(com.ss.android.article.browser.R.id.acy);
        this.d = this.findViewById(com.ss.android.article.browser.R.id.ad1);
        this.e = this.findViewById(com.ss.android.article.browser.R.id.description);
        this.f = this.findViewById(com.ss.android.article.browser.R.id.ad2);
        this.g = this.findViewById(com.ss.android.article.browser.R.id.ad3);
        this.h = this.findViewById(com.ss.android.article.browser.R.id.ad4);
        this.i = this.findViewById(com.ss.android.article.browser.R.id.ad5);
        this.j = this.findViewById(com.ss.android.article.browser.R.id.ad6);
        this.k = this.findViewById(com.ss.android.article.browser.R.id.ad7);
        this.l = this.findViewById(com.ss.android.article.browser.R.id.ad8);
        this.l.setPaintFlags(this.k.getPaintFlags() | 8);
        int v0 = UpdateHelper.getInstance().r() != null ? 1 : 0;
        if(!UpdateHelper.getInstance().m() || !this.m) {
            v1 = 0;
        }

        if(v1 != 0 && v0 != 0) {
            this.a("forcible_downloaded_show");
        }
        else if(v1 != 0) {
            this.a("forcible_show");
        }
        else if(v0 != 0) {
            this.a("downloaded_show");
        }
        else {
            this.a("show");
        }

        this.a();
    }
}

